
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_MonHoc_GetMonHocByTen]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[sp_MonHoc_GetMonHocByTen]
GO
create procedure sp_MonHoc_GetMonHocByTen
	@IndexStart int,
	@Total int,
	@TenMH nvarchar(100)
as
begin			
		With [USER] As ( 
						SELECT	ROW_NUMBER() OVER(ORDER BY MH.MaMH) AS RowNum,
						MH.MaMH,
						MH.Ten_MH,
						MH.Thoi_Gian_Bat_Dau,
						MH.Thoi_Gian_Ket_Thuc,
						MH.Chung_Chi,
						MH.Le_Phi,
						count(DK.MaMH) as TongSVDK
				FROM MonHoc as MH left join DangKy as DK on DK.MaMH=MH.MaMH left join SinhVien as SV on SV.MaSV=DK.MaSV
				WHERE  MH.Ten_MH LIKE @TenMH
				Group By MH.MaMH,MH.Ten_MH,MH.Thoi_Gian_Bat_Dau,MH.Thoi_Gian_Ket_Thuc,MH.Chung_Chi,MH.Le_Phi
		)
		SELECT * FROM [USER] 
		WHERE RowNum BETWEEN @IndexStart AND @Total
end


--execute sp_QLTB_GetNhaCungCapByTen 2,11,'%%'
--sp_ThongKeMonHocByMaSV 'SV01'
--sp_helptext sp_ThongKeMonHocByMaSV
--select * from monhoc
